Proximal Attachment
Piriformis arises as three digitations from the anterior surface of S2 to S4 between and lateral to the sacral foramina, the gluteal surface of the posterior inferior iliac spine, the adjacent sacro-iliac joint capsule and the upper part of the pelvic surface of the sacrotuberous ligament.

Distal Attachment
The muscle emerges from the pelvis through the greater sciatic foramen with the fibers continuing to pass inferiorly, laterally and anteriorly narrowing into a tendon.  Its rounded tendon is attached to the medial side of the upper border and medial aspect of the greater trochanter of the femur, close to the insertion of the obturator internus and the gemelli, with which it may be partially merged.  It may also merge with the gluteus medius.  

Nerve Supply
It is supplied by the nerve to piriformis derived from the ventral rami of L5, S1 and S2.  If the common peroneal nerve leaves the pelvis separately, it may pierce the piriformis muscle, whose anterior surface is intimately related to the sacral plexus.  

The anterior surface of the piriformis is related to the rectum, the sacral plexus and branches of the internal iliac vessels.  Outside the pelvis, the anterior surface is in contact with the posterior surface of the ischium and the capsular hip joint.  Sciatic, posterior femoral cutaneous and pudendal nerves, inferior gluteal and internal pudendal vessels and muscular branches from the sacral plexus, lie in the interval between piriformis and the superior gemellus/obturator internus.

Action
Piriformis laterally rotates the thigh at the hip; abducts the flexed thigh.  It is also an important muscle for holding the head of the femur in the acetabulum.

For more information on the hip see 'The Interactive Hip'.